#include "client.h"

//分析命令
 int send_command(int sockfd){
    train_t command;

    //分析命令，放入结构体
    char buff[1000];
    memset(buff,0,sizeof(buff));
    scanf("%s",buff);

    //判断命令类型
    if(strcmp(buff,"ls")==0){
        //TODO 后面还有东西，就将类型变为 CMD_TYPE_NOTCMD  //不是命令

        command.type=CMD_TYPE_LS;
        command.len=0;
    }//else if()....
    
    Send_Info(sockfd,(char*)&command,sizeof(command.len)+sizeof(command.type)+command.len,0); 

    return 1;
}











/* 下载文件
int transferFile(int sockfd){
//接收文件名
    File file={0,{0}};
    Recv_Info(sockfd,(char *)&file.length,sizeof(file.length),0);
    Recv_Info(sockfd,(char *)&file.content,file.length,0);

    int fd=open(file.content,O_RDWR | O_CREAT |O_TRUNC, 0666);
    ERROR(fd,-1,"open failed")
    //接收文件大小
    memset(&file,0,sizeof(file));
    off_t content_size=0;
    Recv_Info(sockfd,(char *)&file.length,sizeof(file.length),0);
    Recv_Info(sockfd,(char *)&file.content,file.length,0);
    memcpy(&content_size,file.content,file.length);
   
    printf("文件大小：%ld\n",content_size);
    
    //mmap 接收文件内容
    ftruncate(fd,content_size);
    char *p=(char *)mmap(NULL, content_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
    ERROR(p, MAP_FAILED, "mmap")

    Recv_Info(sockfd,p,content_size,0);
    munmap(p,content_size);
    
}
*/
